
#ifndef __DEBUG_PERF_H__
#define __DEBUG_PERF_H__

/*------------------------------------------------------------------------------
    1. External compiler flags
------------------------------------------------------------------------------*/

/* Encoder global definitions
 *
 * _ASSERT_USED     # Asserts enabled
 * _DEBUG_PRINT     # Prints debug information on stdout
 * TRACE_STREAM     # Creates stream trace file
 * TEST_DATA        # Creates test data files
 *
 * Can be defined here or using compiler flags */

/*------------------------------------------------------------------------------
    2. Include headers
------------------------------------------------------------------------------*/
#include <stdio.h>
#include "aos/kernel.h"

#define NDEBUG
#ifdef NDEBUG

#ifndef __DEBUG_PERF_VAR__
#define __DEBUG_PERF_VAR__
int dbg_run_step;
uint32_t dbg_begin_ms, dbg_end_ms, dbg_run_ms, dbg_total_ms;
#else
extern int dbg_run_step;
extern uint32_t dbg_begin_ms, dbg_end_ms, dbg_run_ms, dbg_total_ms;
#endif

#define DBG_PERF_INIT()                             \
    do {                                            \
        dbg_begin_ms = aos_now_ms();                \
        dbg_run_step = 0;                               \
        dbg_run_ms = 0;                                 \
        dbg_total_ms = 0;                               \
    } while(0);
#define DBG_PERF_PRINT()                                                \
    do {                                                                \
        dbg_end_ms = aos_now_ms();                                              \
        dbg_run_ms = dbg_end_ms - dbg_begin_ms;                                              \
        dbg_total_ms += dbg_run_ms;                                             \
        printf("[[[PERF_TIME]]][%s][%d] step=%d, run=%dms, total=%dms\n",              \
               __FUNCTION__, __LINE__, ++dbg_run_step, dbg_run_ms, dbg_total_ms);  \
        dbg_begin_ms = aos_now_ms();                                              \
    } while(0);
#else
#define DBG_PERF_INIT()
#define DBG_PERF_PRINT()
#endif

#endif
